package com.wu.foodsafetyplayer.app.dialog

import android.content.Context
import androidx.fragment.app.FragmentActivity
import com.demo.baseutils.base.BaseUtils
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.impl.LoadingPopupView

/**
 * 加载框工具类
 */
object LoadingUtil {
    private var loadingDialog:LoadingPopupView? = null
    fun showLoading(context:Context,title:String){
        if (loadingDialog == null)
            loadingDialog = XPopup.Builder(context).asLoading()

        loadingDialog?.setTitle(title)?.show()
    }
    fun dismissLoading(context:FragmentActivity){
        /**
         * dismiss()会抛出异常,不能使用try catch
         * 要将更新UI的操作切换到主线程runOnUiThread
         * 在执行关闭的操作
         */
        context.runOnUiThread {
            if (loadingDialog != null)
                loadingDialog?.dismiss()//会抛出异常,不能使用try catch
        }
    }
}